import codecs
import pickle
filepath=r"./sfz.bin"
file=codecs.open(filepath,"rb","utf-8","ignore")#按照指定编码
mylist=file.readlines()#返回一个list,读取到内存
file.close()
print("load")


arealist=[]
filesfz =open("sfz.bin","rb")
arealist=pickle.load(filesfz) #对象的文件加载到内存
filesfz.close()
areafilelist=[] #装下所有文件对象
length=len(arealist)#长度

for  data in arealist:
    kffilepath=data[1]+".txt"
    kffile=open(  kffilepath,"wb")
    areafilelist.append(kffile)

print("create")

for  line  in  mylist:
    linelist=line.split(",") #字符串切割
    chstr=linelist[1][0:6] #取出6个字符
    for  i  in range(length):
        if  str(arealist[i][0])==chstr:#对比是哪个文件
            areafilelist[i].write(line.encode("utf-8"))
            break

print("over")
for  kffile in areafilelist:#关闭文件
    kffile.close()